/*
	Name: 
	Copyright: 
	Author: Karamen
	Date: 21/03/14 12:31
	Description: Mo phong thuat toan sap xep BublleSort
*/

#include <conio.h>
#include <stdio.h>
#include <math.h>
#include <windows.h>
void BubbleSort(int node[] , int n){
	int tmp, i, j;
	for( int i = 0 ; i <  n ; i++){
		for(j = 0 ; j < n- 1 ; j++){
			if(node[j] > node[j + 1]){
				tmp = node[j];
				node[j] = node[j +1 ];
				node[j + 1] = tmp;
			}
		}
	}
}
void xuatMang(int a[], int n){
	for(int i = 0; i< n; i++){
		printf("\t %d",a[i]);
	}
}
void nhapMang(int a[], int n){
	
		printf("\nNhap cac phan tu mang: \n");
		for(int i = 0; i < n ; i++){
			printf("A[%d]=",i);
			scanf("%d",&a[i]);
		}
}
int main(){
	system("PAUSE");
	int array[50],n;
	printf("Nhap vao kich thuoc mang: ");
	scanf("%d",&n);
	nhapMang(array, n);
	printf("\n Mang vua nhap vao la: \n");
	xuatMang(array,n);
	printf("\n Mang Sau khi sap xep theo BubbleSort :\n");
	BubbleSort(array, n);
	xuatMang(array,n);
	getch();
}
